/*
    curlplusplus - a c++ wrapper around libcurl
    Copyright (C) 2012  Francesco "Franc[e]sco" Noferi (francesco1149@gmail.com)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the
    Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
    Boston, MA  02110-1301, USA.
*/

#pragma once

#include <curl/curl.h>
#include <exception>
#include <string>

/**
 * A c++ wrapper around libcurl.
 * @author Francesco "Franc[e]sco" Noferi (francesco1149@gmail.com)
 */
namespace curlpp
{
    /** A generic CURL exception. */
    class exception : public std::exception
    {
    public:
        /**
         * Default constructor.
         * @param info information about the general cause of the error.
         */
        exception(std::string info) throw();

        /**
         * Default destructor
         */
        virtual ~exception() throw();

        /**
         * Returns a C-style character string describing the general cause of the current error.
         * @return a zero-terminated C-style string.
         */
        virtual const char *what() const throw();

    protected:
        std::string info; /**< Stores information about the error passed on the constructor.
                              @see exception(std::string info) */
    };

    /**
     * Reclaims memory that has been obtained through a libcurl call.
     * Use curlpp::free instead of free or delete to avoid anomalies that can result
     * from differences in memory management between your application and libcurl.
     * @see easy::escape()
     * @see easy::unescape()
     */
    void free(char *ptr);

    /**
     * Converts a date string to number of seconds since the epoch (Jan 1, 1970).
     * See <a href="http://curl.haxx.se/libcurl/c/curl_getdate.html">curl_getdate</a> for
     * more info on the string format.
     *
     * @return -1 if it fails to parse the date string, otherwise the converted date
     *            as described.
     */
    time_t getdate(char *datestring);

    /**
     * Gets the libcurl version string.
     * @return a pointer to a zero-terminated string containing the version of libcurl.
     */
    char *version();

    /**
     * Returns runtime libcurl version info. For more information on the usage, see
     * <a href="http://curl.haxx.se/libcurl/c/curl_version_info.html">curl_version_info</a>.
     * @return a pointer to a curl_version_info_data struct.
     * @see version()
     */
    curl_version_info_data *version_info(CURLversion type);
}
